<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>短视频APP-管理系统</title>
        <meta name="keywords" content="短视频APP-管理系统">
        <meta name="description" content="">
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="{$sys_url.static}layui/css/layui.css" media="all">
        <style>
            .frameContent {padding:30px 30px 0px 0px}
            .roleList {float:left;margin:5px 0px;width:33%}
            .frameBtn {text-align:center;margin:20px 0px 0px 30px;padding-top:20px;border-top:1px rgb(204,204,204) dashed}
        </style>
    </head>
    <body>
        <div>
            <form class="layui-form frameContent">
                <!--		
                        <div class="layui-form-item">
                        <div class="layui-form-label">工号</div>
                        <div class="layui-input-block">
                                <input type="text" name="id" required lay-verify="required" placeholder="请输入工号" autocomplete="off" class="layui-input">
                </div>-->
                <div class="layui-form-item">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-inline">
                        <select name="id_position" lay-verify="">
                            {volist name="datas" id="vo"}
                            <option value="{$vo.id}" >{$vo.name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-form-label">图片</div>
                    <div class="layui-input-block">

                        <button type="button" class="layui-btn" id="test1">上传图片</button>
                        
                        <div class="layui-upload-list">
                            <input type="hidden" name="image_url" value="" required lay-verify="required" />
                            <img class="layui-upload-img" id="upload-imge">
                            <p id="demoText"></p>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-form-label">链接地址</div>
                    <div class="layui-input-block">

                        <input type="text" name="link_url"  value=""  required lay-verify="required" placeholder="链接地址" autocomplete="off" class="layui-input" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-label">描述</div>
                    <div class="layui-input-block">
                        <textarea name="description" placeholder="描述" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-label">备注</div>
                    <div class="layui-input-block">
                        <textarea name="memo" placeholder="备注" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="frameBtn">
                    <button class="layui-btn" lay-submit lay-filter="submit">确定新增</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </form>
        </div>
    </body>
    <script src="{$sys_url.static}layui/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form'], function() {
            var form = layui.form;
            var $ = layui.jquery;
            //监听提交
            form.on('submit(submit)', function(data) {
                layer.confirm('是否确定新增？', {icon: 3, title: '系统信息'}, function(index) {
                    $.ajax({
                        url: '{$sys_url.ctr}/add_ajax',
                        type: 'post',
                        data: data.field,
                        dataType: "json",
                        beforeSend: function() {
                            console.log(JSON.stringify(data.field));
                        },
                        success: function(data) {
                            //do something
                            console.log(data);
                            if (data.code == 1) {
                                var index = parent.layer.getFrameIndex(window.name);
                                //获取当前窗口索引
                                parent.layer.msg('添加成功', {icon: 1});
                                parent.layer.close(index);
                                window.parent.location.reload();
                                //重新加载父级tabel数据
                            } else {
                                layer.alert('抱歉，系统繁忙，请稍后再试！', {icon: 2});
                            }
                        },
                        error: function(data) {
                            //do something
                            console.log(data);
                            layer.msg('与服务器连接失败', {icon: 2});
                        }
                    });
                    layer.close(index);
                });
                return false;
            });
        });
        //普通图片上传
        layui.use('upload', function() {
            var $ = layui.jquery
                , upload = layui.upload;
            var uploadInst = upload.render({
                elem: '#test1',
                url: '/Admin/Tool/upload',
                before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#upload-imge').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code == 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $('input[name="image_url"]').val(res.data.route);
                    return;
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        });
    </script>
</html>